1. Field of Invention
Embodiments of the invention relate in general to code optimization. More specifically, the embodiments of the invention relate to methods and systems for optimizing a source code.
2. Description of the Background Art
A series of statements, written in any programming language, is referred to as a source code. Examples of programming languages include, but are not limited to, C, C++, Java, Pascal and Hyper Text Markup Language (HTML). A source code can be either compiled or interpreted to render it executable. Multiple compilation contexts may exist within a source code, yielding different executables. Optimization of a source code may impact multiple executables.
Further, a source code may be organized into several source code files. Some of the source code files may be related to each other. For example, a header file may be included to resolve one or more symbols defined in a C file. Hence, compiling or interpreting a source code file may necessitate the compilation or interpretation of another source code file that is related to the former source code file. For example, with reference to the example mentioned above, compiling the C file may necessitate the compilation of the header file as well.
Compiling or interpreting a large number of source code files in the source code may require a considerable amount of time. A significant part of this compilation or interpretation time can be saved if the source code has been optimized. Optimization of the source code involves conforming to certain coding standards.
The source code may be optimized while it is being generated. However, in the case of source codes with a large number of related source code files, it may be difficult to manage and optimize the source code files during the process of generation. Moreover, after the generation of the source code, it may be necessary to make several changes to it, for the purpose of maintenance. These changes may be made at different times by different programmers, which makes it difficult to keep the source code optimized.
The process of compilation or interpretation of source code files that have not been optimized properly may place an unnecessary burden on a system performing this process. This would affect the overall performance of the system.
Further, some relationships included in the source code may be unnecessary. For example, a header file containing thousands of identifiers may have been included in a C file to resolve only a few identifiers. While compiling the source code, such header files are compiled completely. This may place an unnecessary burden on the system and waste time.
In addition, some relationships in some programming languages are known as named relationships, opaque types or incomplete types, which exist for strong type-checking. While these relationships may be satisfied by a full and complete definition, it may be preferred to satisfy the definition with an incomplete type.